<%@ page language="java" contentType="text/html;charset=UTF-8" %><%@ include file="../../inc/global.jsp" 
%>
<!doctype html>
<html>
<head>
<title>${adminGlobalConfig.name}</title>
<%@include file="../head.jsp" %>
<script type="text/javascript">
function Group() {
	var _this = this;
	this.init = function() {
		$('#save').click(function(){
			_this.save();
		});
		var aids = $('#aids').val().split(',');
		if(aids.length > 0) {
			for(var i=0; i<aids.length; i++) {
				$('#'+aids[i]).addClass('slt');
			}
		}
		$('td').find('em').each(function(){
			$(this).click(function(){
				var aids = $('#aids').val();
				var id = $(this).attr('id');
				if(aids.indexOf(id+',') != -1) {
					$('#aids').val(aids.replace(id+',',''));
					$(this).removeClass('slt');
				} else {
					$('#aids').val(aids + (id+','));
					$(this).addClass('slt');
				}
			});
		});
	};
	this.save = function() {
		$('#save').attr('disabled', 'disabled');
		var url='/a/ajax/staff/group/save';
		var id = $('#id').val();
		var name = $('#name').val();
		var aids = $('#aids').val();
		$.ajax({
			url:url
			, type:'POST'
			, data:{id:id,nm:name,aids:aids}
			, success:function(data){
				var json = $.parseJSON(data);
				if(json.succeed) {
					window.location = "/a/staff/group/list";
				} else {
					alert(json.msg);
				}
				$('#save').removeAttr('disabled');
			}
			,error:function() {
				alert(MSG.ERR);
				$('#save').removeAttr('disabled');
			}
		});
	}
};
var group = new Group();
$(function(){
	group.init();
	$(document).keydown(function(){
		if(event.keyCode == KEY.ENTER) {
			group.save();
		}
	});
	$('#name').focus();
});
</script>
<style type="text/css">
.select em {margin:5px 3px;}
</style>
</head>
<body>
<div class="wrapper">
<%@include file="../header.jsp" %>
<div class="body">
<div class="form">
<table>
<tr>
<th>用户组名称</th>
<td>
<input type="text" id="name" name="name" value="${group.name}" />
</td>
</tr>
<tr>
<th>指定组权限</th>
<td class="select">
<c:forEach var="action" items="${actions}">
<em id="${action.id}">${action.name}</em>
</c:forEach>
</td>
</tr>
<!--  -->
<tr>
<th></th>
<td>
<input type="hidden" id="id" name="id" value="${group.id}" />
<input type="hidden" id="aids" name="aids" value="<c:forEach var="action" items="${gActions}">${action.id},</c:forEach>" />
<input type="button" id="save" name="save" value="确定保存" />
</td>
</tr>
</table>
</div>
<div class="sidebarMenu">
<ul>
<li><a href="/a/staff/group/list">用户组列表</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>